const store = {
    nextId: 1,
    cache: {},
    add: function (fn) {
        if(!fn.id){
            fn.id = this.nextId++;
            this.cache[fn.id] = fn;
            return true;
        }
    }
};

function isPrime(value) {
    if(!isPrime.answers){
        isPrime.answers = {};
    }
    if(isPrime.answers[value] !== undefined) {
        return isPrime.answers[value];
    }
    let prime = value !== 0 && value !== 1;
    for (var i = 2; i < value; i++) {
        if(value % i === 0) {
            prime = false;
            break;
        }
    }
    return isPrime.answers[value] = prime
}

//剩余参数
function multiMax(first, ...remainingNumbers) {
    let sorted = remainingNumbers.sort((a,b)=>b-a);
    return first * sorted[0];
}

//默认参数
//es5的做法
function performAction(ninja, action) {
    action = typeof action === 'undefined' ? "SKULKING" : action;
    return ninja + " " + action
}
//es6的做法
function performAction_es6(ninja ,action="skulking") {
    return ninja + " " + action;
}

var puppet = {
    rules: false
};
function Emperor() {
    this.rules = true;
    return puppet
}
